<?php
require 'fbauth/src/facebook.php';  // Include facebook SDK file
error_reporting(0);
// include_once '_admin/include/sql.php';
$ini = parse_ini_file ( "_admin/config/config.ini" );

$facebook = new Facebook(array(
  'appId'  => $ini["appId"] ,//'830798396934552',   // Facebook App ID 
  'secret' => $ini["secret"],//'53bfc9f3bf4500f608b092643ff4f083',  // Facebook App Secret
  'cookie' => true,	
));
$user = $facebook->getUser();
$loginUrl = "";
if ($user) {
  try {
    $user_profile = $facebook->api('/me');
  	    $fbid = $user_profile['id'];                 // To Get Facebook ID
 	    $fbuname = $user_profile['username'];  // To Get Facebook Username
 	    $fbfullname = $user_profile['name']; // To Get Facebook full name
	    $femail = $user_profile['email'];    // To Get Facebook email ID
	    
	    processLogin($fbid,$fbfullname,$femail,0);
	    echo("<script type='text/javascript'>window.location = \"index.php\";</script>");
	    
  } catch (FacebookApiException $e) {
    error_log($e);
   $user = null;
  }
}
else {
	
 $loginUrl = $facebook->getLoginUrl(array(
		'scope'		=> 'email', // Permissions to request from the user
		));
}
echo '<a class="facebook_btn" href="'.$loginUrl.'"></a>';

?>
